// $Rev: 130 $

#ifndef INCOMING_CONNECTION_H
#define INCOMING_CONNECTION_H

#include <vector>
#include <string>
#include <poll.h>
#include "server.h"
#include "file_index.h"
#include "connection.h"
#include "source.h"


class IncomingConnection : public Source, public Connection {
	public:
		IncomingConnection(Server *server, int socket, pollfd *poll_info);
		void process_events();
		~IncomingConnection();
	private:
		enum FSMState {AWAITING_MESSAGE, SENDING_REPLY};
		void process_command(const std::string &command);
		void hello(const std::vector<std::string> &comm);
		void get_file_listing(const std::vector<std::string> &comm);
		void get_metadata(const std::vector<std::string> &comm);
		void get_sources(const std::vector<std::string> &comm);
		void new_fragment(const std::vector<std::string> &comm);
		void change_state(FSMState newstate);
		std::string buffer, reply;
		Server *server;
		
		FSMState state;
		// No permitimos operadores de copia o asignacion para esta clase.
		IncomingConnection(const IncomingConnection &ic);
		IncomingConnection &operator=(const IncomingConnection &ic);
};

#endif
